import { addcart, getGoodsDetail } from "@/api"

export default {
  namespaced:true,
  state(){
    return {
      goodsDetail:{}
    }
  },
  mutations:{
    setGoodsDetail(state,result){
      state.goodsDetail=result
    }
  },
  actions:{
    async getGoodsDetail({commit},skuId){
      const result=await getGoodsDetail(skuId)
      commit('setGoodsDetail',result.data)
    },
    async addcart({commit},{skuId,skuNum}){
      console.log(commit)
      const result =await addcart(skuId,skuNum)
      if(result.code==200)return 'ok'
      return Promise.reject(new Error('fail'))
    }
  },
  getters:{
    categoryView(state){
      return state.goodsDetail.categoryView||{}
    },
    skuInfo(state){
      return state.goodsDetail.skuInfo||{}
    },
    spuSaleAttrList(state){
      return state.goodsDetail.spuSaleAttrList||[]
    }
  }
}